home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libstiff / sinfo.c.z / sinfo.c
Encoding:
C/C++ Source or Header  |  1996-05-07  |  4.1 KB  |  138 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *           Copyright (c)    1991 Silicon Graphics, Inc.          *
  4.  *            All Rights Reserved                    *
  5.  *                                      *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI          *
  7.  *                                      *
  8.  * The copyright notice above does not evidence any actual of intended      *
  9.  * publication of such source code, and is an unpublished work by Silicon *
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or      *
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly *
  13.  * prohibited.                                  *
  14.  *                                      *
  15.  * RESTRICTED RIGHTS LEGEND:                          *
  16.  *                                      *
  17.  * Use, duplication or disclosure by the Government is subject to      *
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in      *
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR      *
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.      *
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311              *
  24.  **************************************************************************
  25.  *
  26.  * File: sinfo.c
  27.  *
  28.  * Description: Prints detailed information about a STIFF format file.
  29.  *    The header and IFD information is printed. For each IFD the tags
  30.  *    are printed. Offsets for IFD's and data are also displayed.
  31.  *    If a file is not specified on the command-line, stdin is read.
  32.  *
  33.  *    Usage: sinfo [STIFF file]
  34.  *
  35.  **************************************************************************/
  36.  
  37.  
  38. #ident "$Revision: 1.3 $"
  39.  
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <unistd.h>
  44. #include <fcntl.h>
  45. #include <stiff.h>
  46.  
  47.  
  48. main(int argc, char *argv[])
  49. {
  50.     STStream *stptr;         /* Stream TIFF pointer to read */
  51.     STImageHeader ifd;       /* Struct to get image headers */
  52.     int n = 0;               /* Number of images read so far */
  53.     unsigned long ifdOffset; /* Maintains offset of next IFD */
  54.     int input;               /* input file descriptor */
  55.  
  56.     /*
  57.      * input is from file if a file has been specified on the command
  58.      * line, or standard input if no files were specified.
  59.      */
  60.     input = argc > 1 ? open(argv[1], O_RDONLY) : fileno(stdin);
  61.  
  62.     if (input < 0) {
  63.     perror(argv[0]);
  64.     exit(1);
  65.     }
  66.  
  67.     /*
  68.      * Open a TIFF stream
  69.      */
  70.     if ((stptr = STOpen(input, ST_READ)) == NULL) {
  71.     STPerror(argv[0]);
  72.     exit(1);
  73.     }
  74.  
  75.     /*
  76.      * Print file header information
  77.      */
  78.     (void)printf("TIFF Header (offset: 0)\n");
  79.     (void)printf("First IFD at offset: 0x%04lX\n", stptr->next);
  80.     (void)printf("\n");
  81.  
  82.     /*
  83.      * Read and display IFD information until STReadImageHeader
  84.      * returns -1 indicating that no more IFDs can be read from the
  85.      * stream.
  86.      */
  87.     ifdOffset = stptr->next;
  88.     while (STReadImageHeader(stptr, &ifd) == 0) {
  89.     /*
  90.      * Print the offset of this IFD, which we got out of stptr
  91.      * before calling STReadImageHeader
  92.      */
  93.     n++;
  94.     (void)printf("IFD %d (offset: 0x%04lX)\n", n, ifdOffset);
  95.     /*
  96.      * Now update ifdOffset for next time through the loop.
  97.      */
  98.     ifdOffset = stptr->next;
  99.  
  100.     /*
  101.      * Print the tags
  102.      */
  103.     if (STPrintTags(stdout, stptr) < 0) {
  104.         STPerror(argv[0]);
  105.         exit(1);
  106.     }
  107.  
  108.     /*
  109.      * Print the STIFF Image Header structure
  110.      */
  111.     (void)printf("STIFF Image Header\n");
  112.     (void)printf("\tImage width: %lu\n", ifd.width);
  113.     (void)printf("\tImage height: %lu\n", ifd.height);
  114.     (void)printf("\tBits per sample: %u\n", ifd.bitsPerSample);
  115.     (void)printf("\tSamples per pixel: %u\n", ifd.samplesPerPixel);
  116.     (void)printf("\tImage size (bytes): %lu\n", ifd.imgbytes);
  117.     (void)printf("\tImage type: %u\n", ifd.type);
  118.     (void)printf("\tData format: %u\n", ifd.plane);
  119.     }
  120.  
  121.     /*
  122.      * STReadImageHeader will return -1 with STerrno set to STEEOF to
  123.      * indicate that there are no more images.  We don't consider this
  124.      * an error unless no images at all were read in.
  125.      */
  126.     if (STerrno != STEEOF || n == 0) {
  127.     STPerror(argv[0]);
  128.     }
  129.  
  130.     /*
  131.      * Close the TIFF stream
  132.      */
  133.     STClose(stptr);
  134.  
  135.     return 0;
  136. }
  137.  
  138.